package com.zxx.order.presenter

import com.zqq.baselibrary.ext.excute
import com.zqq.baselibrary.http.rx.BaseSubscriber
import com.zqq.baselibrary.presenter.BasePresenter
import com.zxx.order.presenter.iview.EditShipAddressView
import com.zxx.order.service.ShipAddressService
import com.zxx.order.service.bean.ShipAddress
import javax.inject.Inject

/**
 * 编辑收货人信息Presenter
 * wc
 * @author zqq on 2019/6/30.
 */
class EditShipAddressPresenter @Inject constructor() : BasePresenter<EditShipAddressView>() {

    @Inject
    lateinit var shipAddressService: ShipAddressService

    /**
     * 添加收货人信息
     */
    fun addShipAddress(shipUserName: String, shipUserMobile: String, shipAddress: String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()

        shipAddressService.addShipAddress(shipUserName, shipUserMobile, shipAddress)
                .excute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean) {
                        super.onNext(t)
                        mView.onAddShipAddressResult(t)
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        //ceshi
                        mView.onAddShipAddressResult(true)
                    }
                }, lifecycleProvider)
    }


    /**
     * 修改收货人信息
     */
    fun editShipAddress(address: ShipAddress) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        shipAddressService.editShipAddress(address)
                .excute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean) {
                        mView.onEditShipAddressResult(t)
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        mView.onEditShipAddressResult(true)
                    }
                }, lifecycleProvider)

    }


}